const BaseIpcHandler = require('../BaseIpcHandler');
const { spawn } = require('child_process');

// const pythonInterpreter = process.env.PYTHON_PATH || 'python';
// const scriptPath = '/path/to/your/script.py';
// const scriptArgs = ['arg1', 'arg2', 'arg3'];
// const scriptExecution = spawn(pythonInterpreter, [scriptPath].concat(scriptArgs));

// // 捕获标准输出
// scriptExecution.stdout.on('data', (data) => {
//     console.log(`stdout: ${data}`);
// });

// // 捕获错误输出
// scriptExecution.stderr.on('data', (data) => {
//     console.error(`stderr: ${data}`);
// });

// // 脚本执行完成回调
// scriptExecution.on('close', (code) => {
//     console.log(`Python script finished with code: ${code}`);
// });

class RunPythonScriptHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> RunPythonScriptHandler params = ', params);
        const dirs = JSON.parse(params.dirs);

        // 业务逻辑
        let result = { code: 0, msg: '' };

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = RunPythonScriptHandler;
